// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: BG Animation Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 1 : TYPE_BGANIMATION

private alias object.value0 : BGAnimation.BGTimer

// Static Values
public value BGAnimation_value0 = 0;

private alias BGAnimation_value0 : BGAnimation_currentPreview

event ObjectMain

	// Move the camera to the proper position
	BGAnimation.BGTimer++
	BGAnimation.BGTimer &= 511
	Sin(temp0, BGAnimation.BGTimer)
	if temp0 > 0
		if temp0 < 32
			screen.yoffset = 256
		else
			screen.yoffset = 0
		end if
	else
		if temp0 > -32
			screen.yoffset = 512
		else
			screen.yoffset = 768
		end if
	end if

end event


event ObjectDraw

	if stage.actNum == 1 // In the level select scene?

		// Draw the zone preview here

		temp0 = screen.xcenter
		temp0 -= 180
		if temp0 > 0
			temp0 = 0
		end if
		temp0 += screen.xcenter

		// Frame
		DrawSpriteScreenXY(9, temp0, 198)

		// Zone preview
		DrawSpriteScreenXY(BGAnimation_currentPreview, temp0, 198)

	end if

end event


event ObjectStartup

	foreach (TypeName[BG Animation], arrayPos0, ALL_ENTITIES)

		// Set all BG Animation objects to be active
		object[arrayPos0].priority = PRIORITY_ACTIVE

	next

	// Preview frames
        switch stage.playerListPos
	case 0
	case 3
		SpriteFrame(56, -12, 32, 24, 0, 50)
		break
	case 1
		SpriteFrame(56, -12, 32, 24, 181, 35)
		break
	case 2
		SpriteFrame(56, -12, 32, 24, 214, 35)
		break
	end switch
	SpriteFrame(56, -12, 32, 24, 1, 85)
	SpriteFrame(56, -12, 32, 24, 34, 85)
	SpriteFrame(56, -12, 32, 24, 67, 85)
	SpriteFrame(56, -12, 32, 24, 100, 85)
	SpriteFrame(56, -12, 32, 24, 133, 85)
	SpriteFrame(56, -12, 32, 24, 166, 85)
	SpriteFrame(56, -12, 32, 24, 199, 85)
	SpriteFrame(56, -12, 32, 24, 180, 60)

	// Frame
	SpriteFrame(32, -24, 80, 50, 0, 0)

	// Set the preview to GHZ by default
	BGAnimation_currentPreview = 1

end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
